<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer">11063</assigned-user-id>
  <attachments-count type="integer">0</attachments-count>
  <closed type="boolean">true</closed>
  <created-at type="datetime">2009-05-27T11:38:42-04:00</created-at>
  <creator-id type="integer">11063</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer" nil="true"></milestone-id>
  <number type="integer">11</number>
  <permalink>export-folding-is-not-utf-8-safe</permalink>
  <priority type="integer">110629</priority>
  <project-id type="integer">30941</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>resolved</state>
  <tag nil="true"></tag>
  <title>Export Folding is not UTF-8 Safe</title>
  <updated-at type="datetime">2009-05-28T13:32:20-04:00</updated-at>
  <user-id type="integer">8551</user-id>
  <user-name>Fjan</user-name>
  <creator-name>Rick DeNatale</creator-name>
  <assigned-user-name>Rick DeNatale</assigned-user-name>
  <url>http://rick_denatale.lighthouseapp.com/projects/30941/tickets/11</url>
  <original-body>The folding which happens when exporting a calendar currently splits at a fixed character position.

This may cause a UTF-8 string with multi-byte characters to be split producing invalid UTF-8 data.</original-body>
  <latest-body>The folding which happens when exporting a calendar currently splits at a fixed character position.

This may cause a UTF-8 string with multi-byte characters to be split producing invalid UTF-8 data.</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;The folding which happens when exporting a calendar currently
splits at a fixed character position.&lt;/p&gt;
&lt;p&gt;This may cause a UTF-8 string with multi-byte characters to be
split producing invalid UTF-8 data.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer">11063</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>The folding which happens when exporting a calendar currently splits at a fixed character position.

This may cause a UTF-8 string with multi-byte characters to be split producing invalid UTF-8 data.</body>
      <body-html>&lt;div&gt;&lt;p&gt;The folding which happens when exporting a calendar currently
splits at a fixed character position.&lt;/p&gt;
&lt;p&gt;This may cause a UTF-8 string with multi-byte characters to be
split producing invalid UTF-8 data.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-05-27T11:38:42-04:00</created-at>
      <creator-id type="integer">11063</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">11</number>
      <permalink>export-folding-is-not-utf-8-safe</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">30941</project-id>
      <state>new</state>
      <tag nil="true"></tag>
      <title>Export Folding is not UTF-8 Safe</title>
      <updated-at type="datetime">2009-05-27T11:38:42-04:00</updated-at>
      <user-id type="integer">11063</user-id>
      <user-name>Rick DeNatale</user-name>
      <creator-name>Rick DeNatale</creator-name>
      <assigned-user-name>Rick DeNatale</assigned-user-name>
      <url>http://rick_denatale.lighthouseapp.com/projects/30941/tickets/11</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">11063</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Very clever. You only checked the remainder and it worried me that there could be a UTF-8 character that would split into something that was still valid, but I checked the UTF-8 spec and that doesn't seem possible. In fact, you can also determine if you are dealing with a split-in-the-middle character by simply checking if the top two bits are '10', which may be a bit cheaper than String.unpack</body>
      <body-html>&lt;div&gt;&lt;p&gt;Very clever. You only checked the remainder and it worried me
that there could be a UTF-8 character that would split into
something that was still valid, but I checked the UTF-8 spec and
that doesn't seem possible. In fact, you can also determine if you
are dealing with a split-in-the-middle character by simply checking
if the top two bits are '10', which may be a bit cheaper than
String.unpack&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2009-05-28T07:55:09-04:00</created-at>
      <creator-id type="integer">11063</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">11</number>
      <permalink>export-folding-is-not-utf-8-safe</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">30941</project-id>
      <state>new</state>
      <tag nil="true"></tag>
      <title>Export Folding is not UTF-8 Safe</title>
      <updated-at type="datetime">2009-05-28T07:55:11-04:00</updated-at>
      <user-id type="integer">8551</user-id>
      <user-name>Fjan</user-name>
      <creator-name>Rick DeNatale</creator-name>
      <assigned-user-name>Rick DeNatale</assigned-user-name>
      <url>http://rick_denatale.lighthouseapp.com/projects/30941/tickets/11</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">11063</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>I suspect that String.unpack is actually quicker than checking the byte with ruby, since it's a C 'primitive'

In any case I doubt that it makes much performance difference, I trust String#pack to get the utf-8 rules right.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I suspect that String.unpack is actually quicker than checking
the byte with ruby, since it's a C 'primitive'&lt;/p&gt;
&lt;p&gt;In any case I doubt that it makes much performance difference, I
trust String#pack to get the utf-8 rules right.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-05-28T08:34:05-04:00</created-at>
      <creator-id type="integer">11063</creator-id>
      <diffable-attributes type="yaml">--- 
:state: new
</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">11</number>
      <permalink>export-folding-is-not-utf-8-safe</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">30941</project-id>
      <state>resolved</state>
      <tag nil="true"></tag>
      <title>Export Folding is not UTF-8 Safe</title>
      <updated-at type="datetime">2009-05-28T08:34:09-04:00</updated-at>
      <user-id type="integer">11063</user-id>
      <user-name>Rick DeNatale</user-name>
      <creator-name>Rick DeNatale</creator-name>
      <assigned-user-name>Rick DeNatale</assigned-user-name>
      <url>http://rick_denatale.lighthouseapp.com/projects/30941/tickets/11</url>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">11063</assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>By the way, here is what I came up with, slightly shorter but a bit less elegant:

class String
  def ical_wrap
    if (l=self.length)&gt;75 then
      x=75
      begin
        if self[x]&amp;192!=128 then self.insert(x,&quot;\r\n &quot;) # change for Ruby 1.9
        elsif self[x-=1]&amp;192!=128 then self.insert(x,&quot;\r\n &quot;)
        else self.insert(x-=1,&quot;\r\n &quot;)
        end
        x+=77;l+=3
      end while x&lt;l
    end
    self
  end
end</body>
      <body-html>&lt;div&gt;&lt;p&gt;By the way, here is what I came up with, slightly shorter but a
bit less elegant:&lt;/p&gt;
&lt;p&gt;class String&lt;br&gt;
def ical_wrap&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;if (l=self.length)&amp;gt;75 then
  x=75
  begin
    if self[x]&amp;amp;192!=128 then self.insert(x,&quot;\r\n &quot;) # change for Ruby 1.9
    elsif self[x-=1]&amp;amp;192!=128 then self.insert(x,&quot;\r\n &quot;)
    else self.insert(x-=1,&quot;\r\n &quot;)
    end
    x+=77;l+=3
  end while x&amp;lt;l
end
self&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;end end&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-05-28T13:32:19-04:00</created-at>
      <creator-id type="integer">11063</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer" nil="true"></milestone-id>
      <number type="integer">11</number>
      <permalink>export-folding-is-not-utf-8-safe</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">30941</project-id>
      <state>resolved</state>
      <tag nil="true"></tag>
      <title>Export Folding is not UTF-8 Safe</title>
      <updated-at type="datetime">2009-05-28T13:32:20-04:00</updated-at>
      <user-id type="integer">8551</user-id>
      <user-name>Fjan</user-name>
      <creator-name>Rick DeNatale</creator-name>
      <assigned-user-name>Rick DeNatale</assigned-user-name>
      <url>http://rick_denatale.lighthouseapp.com/projects/30941/tickets/11</url>
    </version>
  </versions>
</ticket>
